<%@ Page Title="Member_Withdraw Item" Language="C#" AutoEventWireup="true" CodeBehind="Member_WithdrawItem.aspx.cs" Inherits="Youz.CreditRepay.Manage.Member_WithdrawItem" %>

<script>
    

    var requireJS = [
        //"assets/js/jquery.form.js"
    ];
    loadJS(requireJS);
</script>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h2><i class="fa fa-edit"></i><%: R(LanguageModule.Member_Withdraw, "Member_Withdraw", "Member_Withdraw") %></h2>
            </div>
            <div class="panel-body">
                <form id="frm" class="form-horizontal" method="post" enctype="multipart/form-data" action="Right/Handlers/Member_WithdrawHandler.ashx?type=save">
                    <input id="WithdrawID" name="WithdrawID" type="hidden" />
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="RoleDesc"><%: R(LanguageModule.Member_Withdraw, "CanmentionMoney", "可提金额") %></label>
                                <div class="col-md-9 controls">
                                    <input type="text" maxlength="50" id="CanMentionAmount" style="color: red; font-weight: 700" class="form-control required" readonly="readonly" value="<%:decimal.Round(new Youz.CreditRepay.BLL.Member_AccountBLL().Get(new Youz.CreditRepay.BLL.Member_WithdrawBLL().Get(WebHelper.Get("WithdrawID")).MemberAccount,SiteType.Manage).WithdrawFunds - Youz.CreditRepay.BLL.ConfigParameters.Withdraw.WithdrawAmountShouldStay,2) %>" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="RoleDesc"><%: R(LanguageModule.Member_Withdraw, "WithdrawID", "提现ID") %></label>
                                <div class="col-md-9 controls">
                                    <input type="text" maxlength="50" id="_WithdrawID" class="form-control required" readonly="readonly" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="RoleDesc"><%: R(LanguageModule.Member_Withdraw, "MemberAccount", "会员帐号") %></label>
                                <div class="col-md-9 controls">
                                    <input type="text" id="MemberAccount" name="MemberAccount" maxlength="50" class="form-control required" readonly="readonly" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="RoleDesc"><%: R(LanguageModule.Member_Withdraw, "Status", "状态") %></label>
                                <div class="col-md-9 controls" id="Status">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="RoleDesc"><%: R(LanguageModule.Member_Withdraw, "WithdrawAmount", "提现金额") %></label>
                                <div class="col-md-9 controls">
                                    <input type="text" id="WithdrawAmount" name="WithdrawAmount" maxlength="9" class="form-control required" readonly="readonly" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="RoleDesc"><%: R(LanguageModule.Member_Withdraw, "WithdrawFee", "手续费") %></label>
                                <div class="col-md-9 controls">
                                    <input type="text" id="WithdrawFee" name="WithdrawFee" maxlength="9" class="form-control" readonly="readonly" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="RoleDesc"><%: R(LanguageModule.Member_Withdraw, "BankName", "银行名称") %></label>
                                <div class="col-md-9 controls">
                                    <input type="text" id="BankName" name="BankName" maxlength="200" class="form-control required" readonly="readonly" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="RoleDesc"><%: R(LanguageModule.Member_Withdraw, "BankAccountNo", "银行账户号") %></label>
                                <div class="col-md-9 controls">
                                    <input type="text" id="BankAccountNo" name="BankAccountNo" maxlength="200" class="form-control required" readonly="readonly" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="RoleDesc"><%: R(LanguageModule.Member_Withdraw, "BankAccountName", "银行賬戶名") %></label>
                                <div class="col-md-9 controls">
                                    <input type="text" id="BankAccountName" name="BankAccountName" maxlength="200" class="form-control" readonly="readonly" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="RoleDesc"><%: R(LanguageModule.Member_Withdraw, "BankProvince", "银行所在省份") %></label>
                                <div class="col-md-9 controls">
                                    <input type="text" id="BankProvince" name="BankProvince" maxlength="400" class="form-control" readonly="readonly" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label"><%: R(LanguageModule.Member_Recharge, "CreateTime", "创建时间") %></label>
                                <div class="col-md-9">
                                    <input type="text" id="CreateTime" name="CreateTime" maxlength="20" class="form-control" readonly="readonly" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label"><%: R(LanguageModule.Member_Recharge, "ModifyTime", "修改时间") %></label>
                                <div class="col-md-9">
                                    <input type="text" id="ModifyTime" name="ModifyTime" maxlength="20" class="form-control" readonly="readonly" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="RoleDesc"><%: R(LanguageModule.Member_Recharge, "AuditOpinion", "审核意见") %></label>
                                <div class="col-md-9">
                                    <textarea id="AuditOpinion" name="AuditOpinion" rows="2" maxlength="100" class="form-control"></textarea>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-3 control-label"><%: R(LanguageModule.Member_Recharge, "AuditTime", "审核时间") %></label>
                                <div class="col-md-9">
                                    <input type="text" id="AuditTime" name="AuditTime" maxlength="100" class="form-control" readonly="readonly" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="alert alert-danger" style="display: none;">
                        <button type="button" class="close" data-dismiss="alert">×</button><strong>Oh snap!</strong><span class="content"></span>
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-actions">
                                <label class="col-md-3 control-label"></label>
                                <div class="col-md-9">
                                    <button class="btn btn-primary" type="button" id="btnReview" onclick="btnAudit('','<%:(int)Youz.CreditRepay.Entity.WithdrawStatus.Review %>')"><%: R(LanguageModule.M_Common, "Review", "审核中") %></button>
                                    <button class="btn btn-success" type="button" id="btnBy" onclick="btnAudit('你确定要通过此提现记录吗？','<%:(int)Youz.CreditRepay.Entity.WithdrawStatus.Completed %>')"><%: R(LanguageModule.M_Common, "by", "通过") %></button>
                                    <button class="btn btn-success" type="button" id="btnNoBy" onclick="btnAudit('你确定要打回此提现记录吗？','<%:(int)Youz.CreditRepay.Entity.WithdrawStatus.NotPassed %>')"><%: R(LanguageModule.M_Common, "noby", "不通过") %></button>
                                    
                                    <button class="btn btn-danger" type="button" id="btnPayment">获取代付状态</button>
                                    <button class="btn btn-default" type="button" id="btnCancel"><%: R(LanguageModule.M_Common, "btnCancel", "取消") %></button>
                                    <div style="color: red; display: none;" id="display">该会员账户可提金额小于0,无法审核通过！</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    var flag = false;

    function validate() {
        return $("#frm").valid();
    };

    function WStatus(value) {
        switch (value) {
            case 1:
                return '<span class="label label-info"><%: R(LanguageModule.Member_Withdraw, "Pending", "待审核") %></span>';
                break;
            case 2:
                return '<span class="label label-primary"><%: R(LanguageModule.Member_Withdraw, "Review", "审核中") %></span>';
                break;
            case 3:
                return '<span class="label label-danger"><%: R(LanguageModule.Member_Withdraw, "Fail", "审核未通过") %></span>';
                break;
            case 4:
                return '<span class="label label-success"><%: R(LanguageModule.Member_Withdraw, "Completed", "已完成") %></span>';
                break;
            case 5:
                return '<span class="label label-default"><%: R(LanguageModule.Member_Withdraw, "Revoked", "已撤消") %></span>';
                break;
            case 6:
                return '<span class="label label-primary"><%: R(LanguageModule.Member_Withdraw, "Submit", "代付中") %></span>';
                break;

        }
    };

    function get() {
        $.post("Member/Handlers/Member_WithdrawHandler.ashx?type=get", { WithdrawID: "<%= WebHelper.Get("WithdrawID") %>" }, function (data) {
            $('#frm').fill(data);
            $("#_WithdrawID").val(data.WithdrawID);
            $("#MoneyType").attr("value", data.MoneyType);
            $("#Status").html(WStatus(data.Status));
            $("#BankProvince").val(data.BankProvince + " " + data.BankCity);
        }, 'json');

        //审核信息
        var RecordTable = 'Member_Withdraw';
        var RecordType = 'Status';
        var ObjectID = "<%= WebHelper.Get("WithdrawID") %>";
        $.post("Sys/Handlers/Sys_StatusRecordHandler.ashx?type=getAuditRecord", { RecordTable: RecordTable, RecordType: RecordType, ObjectID: ObjectID }, function (data) {
            if (data != null) {
                $("#AuditTime").val(data.CreateTime);
                $("#AuditOpinion").val(data.Memo);
            }
        }, 'json');
    }

    $(function () {
        $("#frm").validate({
            errorElement: "span"
        });

        get();
        if ("<%= WebHelper.Get("Status") %>" == "<%=(int)Youz.CreditRepay.Entity.WithdrawStatus.Completed %>" || "<%= WebHelper.Get("Status") %>" == "<%=(int)Youz.CreditRepay.Entity.WithdrawStatus.NotPassed %>" || "<%= WebHelper.Get("Status") %>" == "<%=(int)Youz.CreditRepay.Entity.WithdrawStatus.Revoked %>") {
            $("#btnBy").hide();
            $("#btnNoBy").hide();
            $("#btnReview").hide();
            $("#AuditOpinion").attr("readonly", "readonly");
        }
        if ("<%= WebHelper.Get("Status") %>" == "<%=(int)Youz.CreditRepay.Entity.WithdrawStatus.Review %>") {
            $("#btnReview").hide();
        }
        if ($("#CanMentionAmount").val() < 0) {
            $("#btnBy").hide();
            $("#display").css("display", "block");
        }

        $("#frm").ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, $form, options) {
                if (flag) {
                    return false;
                }
                else {
                    flag = true;
                    return true;
                }
            },
            success: function (data) {
                if (data.isSuccess) {
                    loadPage("Member/Member_WithdrawList.aspx");
                }
                else {
                    $(".alert > .content").html(data.message);
                    $(".alert").show();
                }
                flag = false;
            }
        });

        $("#btnCancel").click(function () {
            loadPage("Member/Member_WithdrawList.aspx");
        });

        $("#btnPayment").click(function () {
            $.post("PayEase/Handlers/PayEaseHandler.ashx?type=GetStatus", { ID: "<%= WebHelper.Get("WithdrawID") %>" }, function (data) {
                console.log(data);
                if (data.isSuccess){
                    get();
                }
                    $(".alert > .content").html(data.message);
                    $(".alert").show();
            }, "json");
        });
    });
    function btnAudit(text, status) {
        if (status == '<%:(int)Youz.CreditRepay.Entity.WithdrawStatus.NotPassed%>' && $("#AuditOpinion").val().trim() == "") {
            jalert("审核不通过时需填写审核意见!");
            return false;
        }
        if (status == '<%:(int)Youz.CreditRepay.Entity.WithdrawStatus.Completed%>' && $("#CanMentionAmount").val() < 0) {
            jalert("可提金额小于0时，审核无法通过!");
            return false;
        }
        $('#confirm .btn-primary').unbind('click');
        if (text.trim() == "") {
            Sajax(status);
        } else {
            jconfirm("" + text + "", function () {
                Sajax(status);
            })
        }
    };
    function Sajax(status) {
        $.ajax({
            type: "POST",
            dataType: "html",
            url: 'Member/Handlers/Member_WithdrawHandler.ashx?type=audit',
            data: { WithdrawID: "<%= WebHelper.Get("WithdrawID") %>", Status: status, AuditOpinion: $("#AuditOpinion").val() },
            success: function (data) {
                var strresult = eval("(" + data + ")");
                if (strresult.isSuccess) {
                    loadPage("Member/Member_WithdrawList.aspx");
                } else {
                    jalert(strresult.message);
                }
            },
            error: function (data) {
                // alert("error:" + data.responseText);
            }

        });
    }
</script>
